<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout" xmlns:form="http://www.w3.org/1999/html"
      layout:decorator="admin/public/layout">

<head>
    <title>新建用户</title>
</head>
<div  layout:fragment="content">
    <section class="content-header">
        <h1>
            新建用户
            <small>添加新用户</small>
        </h1>
    </section>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div th:include="/admin/public/error"></div>
                <div class="box box-default">
                    <form th:object="${user}" role="form" name="userForm" method="POST" th:action="@{/admin/user/create}">
                        <div class="box-body">
                            <div  th:class="${#fields.hasErrors('username')}?'form-group has-error':'form-group'" >
                                <label>用户名</label>
                                <input type="text" name="username" class="form-control "  placeholder="用户名" th:value="${user.username}" />
                                <p th:if="${#fields.hasErrors('username')}" class="help-block" th:text="${#fields.errors('username')[0]}"></p>
                            </div>
                            <div th:class="${#fields.hasErrors('email')}?'form-group has-error':'form-group'">
                                <label>邮箱</label>
                                <input type="email" name="email" class="form-control"  placeholder="邮箱" th:value="${user.email}">
                                <p th:if="${#fields.hasErrors('email')}" class="help-block" th:text="${#fields.errors('email')[0]}"></p>
                            </div>
                            <div th:class="${#fields.hasErrors('password')}?'form-group has-error':'form-group'">
                                <label>密码</label>
                                <input type="text" name="password" class="form-control"  placeholder="密码" th:value="${user.password}">
                                <p th:if="${#fields.hasErrors('password')}" class="help-block" th:text="${#fields.errors('password')[0]}"></p>
                            </div>
                            <div th:class="${#fields.hasErrors('roleIds')}?'form-group has-error':'form-group'">
                                <label>角色</label>
                                <select class="form-control" name="roleIds">
                                    <option th:each="role:${roles}" th:value="${role.id}" th:text="${role.name}"> </option>
                                </select>
                                <p th:if="${#fields.hasErrors('roleIds')}" class="help-block" th:text="${#fields.errors('roleIds')[0]}"></p>
                            </div>
                        </div>
                        <div class="box-footer">
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>
